﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true"
    CodeBehind="SampleCustomErrorHandling.aspx.cs" Inherits="OpenWaves.ActivityFeed.Web.Tests.Samples.SampleCustomErrorHandling" %>

<%@ Register Src="~/Samples/SampleDescription.ascx" TagName="SampleDescription" TagPrefix="c" %>


<asp:Content ContentPlaceHolderID="head" runat="server">
    <style type="text/css" media="all">
        .ui-dialog-buttonset
        {
            font-size: 10px;
        }
        
        .ui-dialog-content, .ui-dialog-title
        {
            font-size: 14px;
        }
        
        .row {
            padding-left: 50px;
            display: block;
        }        
        
        .row label {
            width: 100px;
        }
        
    </style>
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $("#dialog-error").dialog({
                autoOpen: false,
                resizable: false,
                height: 200,
                width: 450,
                modal: true,
                buttons: {
                    "Ok": function () {
                        $(this).dialog("close");
                    }
                }
            });
        });
        
        
        function showError(exception) {
            $("#dialog-error #errorCode").text(exception.status);
            $("#dialog-error #errorText").text(exception.statusText);
            $("#dialog-error").dialog("open");
        }

        activityFeed.api.handleError = function (exception) {
            if (exception.status == 401) {
                window.location = '<%= Page.ResolveUrl("~/Login.aspx") %>';
            }
            else {
                showError(exception);
            }
        };

    </script>
</asp:Content>


<asp:Content ContentPlaceHolderID="cphBody" runat="server">

<c:SampleDescription ID="SampleDescription1" runat="server">
    <MessageTemplate>
        <p>In this example, after 401 error occur, user is redirected to login page. Otherwise, dialog window with error text appear.</p>
        <p>To test this situation, you can use Fiddler->AutoResponder, and set as rule '/activityFeed/updates'</p>
    </MessageTemplate>
</c:SampleDescription>   


    <h3>Custom errors handling</h3>

    <ow:ActivityFeed runat="server" />

    <div id="dialog-error" title="Error occured" style="display: none">
        <p><span class="ui-icon ui-icon-alert"></span>
        <span class="row">
            <label>Error code:</label><span id="errorCode"></span>
        </span>
        <span class="row">
            <label>Error message:</label><span id="errorText"></span>
        </span>
        </p>    
    </div>
</asp:Content>
